package com.ffdms.mobileoffice;

import java.util.List;

import com.ffdms.util.LoggerUtil;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class PlanDashboardListAdapter extends BaseAdapter {
	private Context context;
	private List<PlanDashboardInfo> plans;

	public PlanDashboardListAdapter(Context context,
			List<PlanDashboardInfo> plans) {
		this.context = context;
		this.plans = plans;
		LoggerUtil.log(LoggerUtil.LOG_D, "single_plan img:"
				+ plans.get(5).getImg());
	}

	@Override
	public int getCount() {
		return plans.size();
	}

	@Override
	public Object getItem(int position) {
		return plans.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.plan_dashboard_item_view, null);
			holder = new ViewHolder();
			holder.iv_plan_dashboard = (ImageView) convertView
					.findViewById(R.id.iv_plan_dashboard);
			holder.tv_plan_dashboard = (TextView) convertView
					.findViewById(R.id.tv_plan_dashboard);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (plans != null) {
			PlanDashboardInfo plan = plans.get(position);
			holder.iv_plan_dashboard.setBackgroundResource(plan.getImg());
			holder.tv_plan_dashboard.setText(plan.getTitle());
		}
		return convertView;
	}

	 class ViewHolder {
		ImageView iv_plan_dashboard;
		TextView tv_plan_dashboard;
	}

}
